package puzzle.game;

import java.io.File;
import java.util.ArrayList;
import puzzle.core.LevelData;
import puzzle.game.MapList;

public class MapList extends ArrayList<MapList.Entry> {
  
  public MapList(int i) {
    super(i);
  }
  
  public MapList() {
  }
  
  public LevelData getData(int i) {
    return get(i).getData();
  }
  
  public String getPath(int i) {
    return get(i).getPath();
  }
  
  public static class Entry {
    private String path;
    private LevelData data;
    private File f;
    
    public Entry(String s, LevelData d) {
      this.path = s;
      this.data = d;
      this.f = new File(s);
    }
    
    public File getFile() {
      return f;
    }
    
    public String getPath() {
      return path;
    }
    
    public LevelData getData() {
      return data;
    }
    
    public boolean equals(Object o) {
      if (o instanceof Entry) {
        Entry e = (Entry)o;
        return this.getPath().equals(e.getPath());
      }
      else
        return false;
    }
    
    public String toString() {
      String name = getData().getName();
      String author = getData().getAuthor();
      
      if (name==null||name.length()==0) {
        return getFile().getName();
      }
      
      String str = name +
                    (
                      (author!=null&&author.length()!=0)
                        ? " (by "+author+")"
                        : ""
                    );
      return str;
    }
  }
}
